import axios from "axios";
const mallId=JSON.parse(localStorage.getItem('u-data'))?JSON.parse(localStorage.getItem('u-data')).mallId.slice(0,1):5
console.log(mallId);
const baseURL=`https://sdc.dev.dgyunju.cn/web/index.php?_mall_id=${mallId}&r=`
let requset = axios.create({
  baseURL,
  timeout: 5000,
});

requset.interceptors.request.use((config) => {
    const token = localStorage.getItem('u-token')
    
    if (token) {
      config.headers.Token = `${token}`
    }
    return config
  })
  requset.interceptors.response.use(
    res => {
      const { status } = res
      if (status==200) {
        return res.data
      } else {
        return Promise.reject(new Error(res.data.msg))
      }
    },
    err => {
      return Promise.reject(err)
    }
  )
 
export default requset;